package com.zch.application;

public class Person extends Animal{
    /*
        封装的好处：
        1.隐藏实现细节：方法(连接数据库)<--调用(传参)
        2.可以对数据进行验证，保证安全合理
     */
    public String name;
    private int age;
    private char gender;
    public static int count;
    public final double TAX_RATE = 0.05;
    /*
        final修饰的类无法被继承
        final修饰的成员方法无法被重写
        final修饰的局部变量或属性无法被修改
     */

    //static {}或{} 静态代码块和代码块，加载类时或创建对象时隐式调用

    public boolean equals(Object obj) {
        if(this == obj) {
            return true;
        }
        if (obj instanceof Person) {
            Person person = (Person)obj;
            return this.age == person.age && this.gender == person.gender && this.name.equals(person.name);
        }
        return false;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", gender=" + gender +
                '}';
    }

    public Person() {
        System.out.println("P无参构造");
    }

    /*
        构造器：
        1.和类名相同
        2.没有返回值
        3.初始化对象的值
    */

    public Person(String name, int age, char gender) {
        setName(name);
        setAge(age);
        setGender(gender);
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        if(name.length() >= 2 && name.length() <= 6) {
            this.name = name;
        } else {
            System.out.println("Name must be between 2 and 6 characters");
            this.name = null;
        }
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        if(age >= 0 && age <= 100) {
            this.age = age;
        } else {
            System.out.println("Age must be between 0 and 100");
            this.age = 18;
        }
    }

    public char getGender() {
        return gender;
    }

    public void setGender(char gender) {
        this.gender = gender;
    }

    public void showInfo() {
        System.out.println("Name: " + name + ", Age: " + age + ", Gender: " + gender);
    }

    public void join() {
        System.out.println(name + "加入...");
    }

    public void print(){
        System.out.println("com.zch.application.Person");
    }

    public void print(String name){
        System.out.println(name);
    }
    /*
        方法重载注意：
        1.方法名相同
        2.参数列表必须不同
        3.返回类型无要求
     */

    public void eat(){
        System.out.println("人在吃");
    }


    public void run(){
        System.out.println("人在跑");
    }

    //静态方法中不能使用this参数
    public static void read(){
        System.out.println("人在读书");
    }

}
